-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Extend support for logging a collection #7771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7771 +/- ##
======================================
- Coverage 93% 92% -0%
======================================
Files 199 199
Lines 12985 12979 -6
======================================
- Hits 12018 11978 -40
- Misses 967 1001 +34 |
justusschock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general. There are a few typing things that are unrelated to this PR, but since it's a rather small one, I think it should be fine.
tchaton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM !
| def log_dict( | ||
| self, | ||
| dictionary: dict, | ||
| dictionary: Dict[str, _METRIC_COLLECTION], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type here is interesting.
If this is read-only, let's use Mapping[str, _METRIC_COLLECTION] which is covarient with the value type of the key (meaning that Mapping[str, torch.Tensor] and Mapping[str, Metric]`) are both subtypes, and will validate type checking.
Since Dict implies mutability (eg, the function might mutate the dictionary), the type checker defines it as invariant. As such, Dict[str, torch.Tensor] is NOT a valid type to pass to to a function accepting Dict[str, Union[torch.Tensor, Metric]]). See here for discussion: python/mypy#2300 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! I did not know that.
Feel free to open a patch with the change. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a minor type-only change, sent it out with #7851.
What does this PR do?
Includes part of the changes to properly support
self.log('foo', {...}):Nonelog valuesDocumentation and tests for this feature will come in later PRs
Part of #7631
Before submitting
PR review